<?php

/**
 * Author: Jesse
 * Email : jessedev@163.com
 * Date: 2024/6/15 11:42
 * FileName: OrderService.php
 * DESC: The Relentless Pursuit of Perfection.
 */

namespace App\Services;

use ApiClient\Order\Interfaces\OrderServiceInterface;
use ApiClient\Order\Producer\DemoProducer;
use App\Model\OrderModel;
use Common\Constants\ResponseCode;
use Common\Kernel\Exception\BusinessException;
use Hyperf\Amqp\Producer;
use Hyperf\Di\Annotation\Inject;
use Hyperf\RpcServer\Annotation\RpcService;

#[RpcService(name: 'OrderService', server: 'jsonrpc', protocol: 'jsonrpc', publishTo: 'nacos')]
class OrderService implements OrderServiceInterface
{
    #[Inject]
    protected Producer $producer;
    /**
     * 获取订单列表
     *
     * @param array $params
     * @return array
     */
    public function getList(array $params = []): array
    {
//        throw new BusinessException(ResponseCode::ERROR);
        logger()->debug('测试阶段');
        return OrderModel::get()->toArray();
    }

    /**
     * 测试队列
     *
     * @param array $params
     * @return array
     */
    public function testQueue(array $params = []): array
    {
        return [
            'result' => $this->producer->produce(new DemoProducer($params)),
        ];
    }
}